<template>
    <div class="update-photo">
        <div><van-image class="img" :src="img" ref="img" /></div>
        <div class="toolbar">
            <div @click="$emit('close')">取消</div>
            <div @click="onConfirm">确定</div>
        </div>
    </div>
</template>
<script>
import Cropper from 'cropperjs'
import 'cropperjs/dist/cropper.css'

export default {
    props: {
        img: {
            type: String,
            required: true
        }
    },
    data() {
        return {
            myCropper: {},
        }
    },
    created() {

    },
    mounted() {
        console.log(this.$refs);
        try {
            const image = this.$refs.img
            console.log(image);
            this.myCropper = new Cropper(image1, {
                viewMode: 1,
                dragMode: 'move',
                initialAspectRatio: 1,
                aspectRatio: 1,
                cropBoxMovable: false,
                preview: '.before',
                background: false,
                autoCropArea: 0.6,
                movable: true,
                zoomOnWheel: false,
            })
        } catch (error) {
            console.log(error);
        }
        
    },
    methods: {
        init(){
            
        },
        onConfirm() {
            console.log(this.myCropper.getCanvasData());
        }
    }
}
</script>
<style lang="less" scoped>
.update-photo {
    .toolbar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: #fff;
        display: flex;
        justify-content: space-between;
        div {
            font-size: 18px;
            margin: 10px;
        }
    }
    .img {
        display: block;
        max-width: 100%;
    }
}
    
</style>